package com.ikcai.common.freemark.extend;

import java.io.IOException;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import com.jagregory.shiro.freemarker.ShiroTags;
import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModelException;
/**
 * 标题:
 * 功能:
 * @Author: 赵力
 * @Class: com.ikcai.common.freemark.extend.FreeMarkerConfigExtend
 * @Date: 2017/8/23 下午9:09
 * @desc:
 * @Copyright: ikcai.com@2017
 */
public class FreeMarkerConfigExtend extends FreeMarkerConfigurer {
    @Override
    public void afterPropertiesSet() throws IOException, TemplateException {
        super.afterPropertiesSet();
        Configuration cfg = this.getConfiguration();
        putInitShared(cfg);
    }

    public static void put(Configuration cfg,String k,Object v) throws TemplateModelException{

        cfg.setSharedVariable(k,v);
        cfg.setNumberFormat("#");//防止页面输出数字,变成2,000
    }
    public static void putInitShared(Configuration cfg) throws TemplateModelException{
        //shiro tag
        put(cfg,"shiro", new ShiroTags());
    }
}
